/*
 *  flyingBall.h
 *  fadeout3d_ycam
 *
 *  Created by rhizomacbookPro6 on 1/26/11.
 *  Copyright 2011 Rhizomatiks. All rights reserved.
 *
 */
#include "ofMain.h"
#include "ball.h"
#pragma once

class flyingBall : public ball {
public:	
	
	flyingBall(int _w, int _h){
		widthSpiral = _w;
		heightSpiral = _h;
		angle = 0;
		z = 0;
		r = widthSpiral / 2.0f;	
//		cout << "createFlying ball z = " << z << endl;
	}
	
	void updateAngle(){
		posNormalized.x = x/(float)w;
		posNormalized.y = y/(float)h;
		
		float xNormalizedForSpiral = (age % (w * 2) ) /(float)(w * 2) ;
		angle = 360.0 * xNormalizedForSpiral;
		
		ageNormalized = age / (float)(w * h);
		
//		float deltaZ = heightSpiral / (float)h / (float)w;
//		z += deltaZ;
//		z = posNormalized.y * deltaZ;
		z = ageNormalized * heightSpiral;
		float px = r * cos(ofDegToRad(angle));
		float py = r * sin(ofDegToRad(angle * 2)) * 0.555;
		pos3D.set(px, z, py);
	}

	void updateAngleWithAge(int _myage){
		int myage = _myage;
		posNormalized.x = x/(float)w;
		posNormalized.y = y/(float)h;
		
		float xNormalizedForSpiral = (myage % (w * 2) ) /(float)(w * 2) ;
		angle = 360.0 * xNormalizedForSpiral;
		
		ageNormalized = myage / (float)(w * h);		
		z = ageNormalized * heightSpiral;
		float px = r * cos(ofDegToRad(angle));
		float py = r * sin(ofDegToRad(angle * 2)) * 0.555;
		pos3D.set(px, z, py);
	}
	
	void drawSpiral(){
		float px = y % 2 ==0 ? w - x - 1 : x;
		ofSetColor(col.r, col.g, col.b);		
		ofPushMatrix();
		ofTranslate(pos3D.x, pos3D.y, pos3D.z);
			ofSphere(0, 0, 0, 3);
		ofPopMatrix();
	}
		
	float getAngle(){
		return angle;
	}
	
	float angle;
	float z;
	float r;

	ofVec3f pos3D;
	ofVec3f posNormalized;
	float ageNormalized;	
	int widthSpiral;
	int heightSpiral;
};